package test;

import pojo.Employee;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Shangji2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException, InvocationTargetException {
        Class clz = Employee.class;
        Employee e = (Employee) clz.newInstance();
        Field empNo = clz.getDeclaredField("empNo");
        Field empName = clz.getDeclaredField("empName");
        Field empPost = clz.getDeclaredField("empost");
        Field empSalary = clz.getDeclaredField("empSalary");
        empNo.setAccessible(true);
        empName.setAccessible(true);
        empPost.setAccessible(true);
        empSalary.setAccessible(true);
        System.out.println(empNo.get(e) + " " + empName.get(e) + " " + empPost.get(e) + " " + empSalary.get(e));
        empName.set(e, "刘敦熙");
        empNo.set(e, "007");
        empPost.set(e, "捡垃圾");
        empSalary.set(e, 3000.0);
        System.out.println(empNo.get(e) + " " + empName.get(e) + " " + empPost.get(e) + " " + empSalary.get(e));
        System.out.println("------------上机三------------");

        Method xinxi = clz.getMethod("showInfo");
        xinxi.invoke(e);
    }
}
